package com.jadobo.xswing.util;

import java.util.Iterator;

import org.w3c.dom.NodeList;
import org.w3c.dom.Node;

public class NodeListAdapter 
	implements Iterator<Node>, Iterable<Node> {
	
	private NodeList nodeList;
	private int counter = 0;
	
	public NodeListAdapter(NodeList nodeList) {
		this.nodeList = nodeList;
		
	}

	@Override
	public boolean hasNext() {
		return counter < nodeList.getLength();
	}

	@Override
	public Node next() {
		return nodeList.item(counter++);
	}

	@Override
	public void remove() {
		throw new IllegalArgumentException("Node deletion is not allowed.");
		
	}

	@Override
	public Iterator<Node> iterator() {
		
		return this;
	}

}
